#ifndef DxUtils_h__
#define DxUtils_h__

#include <d3d11.h>
#include "dxerr.h"

namespace PracEng
{
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)      { if (p) { (p)->Release(); (p)=NULL; } }
#endif

#ifndef SAFE_RELEASE_ARRAY
#define SAFE_RELEASE_ARRAY(p) { for(auto obj : (p)) {SAFE_RELEASE(obj)} }
#endif

#if defined(DEBUG) || defined(_DEBUG)
#ifndef TRACE_HR
#define TRACE_HR(x) { if(FAILED( (x) )) {DXTRACE_ERR_MSGBOX(L#x, (x));} }
#endif
#ifndef RETURN_TRACE_HR
#define RETURN_TRACE_HR(x) { if(FAILED( (x) )) { return DXTRACE_ERR_MSGBOX(L#x, (x)); } }
#endif
#ifndef BOOL_RETURN_TRACE_HR
#define BOOL_RETURN_TRACE_HR(x) { if(FAILED( (x) )) {DXTRACE_ERR_MSGBOX(L#x, (x)); return false; } }
#endif
#else
#ifndef TRACE_HR
#define TRACE_HR(x) { (x); }
#endif
#ifndef RETURN_TRACE_HR
#define RETURN_TRACE_HR(x) { (x); }
#endif
#ifndef BOOL_RETURN_TRACE_HR
#define BOOL_RETURN_TRACE_HR(x) {  (x); }
#endif
#endif

	template<UINT TNameLength>
	inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char(&name)[TNameLength])
	{
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
		resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
#else
		UNREFERENCED_PARAMETER(resource);
		UNREFERENCED_PARAMETER(name);
#endif
	}


}

#endif // DxUtils_h__
